<template>
  <div>
    <!-- 卡片视图 -->
    <el-card>
      <el-row>
        <el-col >
          <!-- 搜索框 -->
       <div>
          <el-input
            style="width: 200px"
            v-model="search"
            placeholder="输入关键字搜索"
          />
    
          <el-button
            icon="el-icon-refresh"
             style="margin-left: 5rem"
            type="primary"
            @click="handleRefresh"
            >刷新</el-button
          >
        </div>
        </el-col>
      </el-row>
      <br>
      <el-table :data="orderList.filter(
          (data) =>
            !search ||
            data.order_number.toLowerCase().includes(search.toLowerCase())
        )" style="width: 100%" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="width"
        ></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="width"
        ></el-table-column>
        <el-table-column label="是否付款" width="width">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="点击发货" width="width" >
          <template slot-scope="scope" >
            <el-tag type="success" v-if="scope.row.is_send === '1'" 
              >已发货</el-tag
            >
            <el-tag type="danger" v-else @click="issend(scope.$index,scope.row)">未发货</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" width="width">
          <template slot-scope="scope">{{ scope.row.create_time }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <!-- 修改按钮 -->
          <el-tooltip
            class="item"
            effect="dark"
            content="修改订单地址"
            placement="bottom-end"
          >
            <el-button
              type="primary"
              icon="el-icon-edit"
              circle
              size="small"
              @click="showBox"
            ></el-button>
          </el-tooltip>
          <!--物流进度按钮  -->
          <el-button
            type="success"
            icon="el-icon-location"
            circle
            size="small"
            @click="showProgressBox"
          ></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editBoxDialogVisible"
      width="50%"
      @close="addressDialogClosed"
    >
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            :options="cityData"
            v-model="addressForm.address1"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editBoxDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm()"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流信息"
      :visible.sync="ProgressDialogVisible"
      width="50%"
    >
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>

    

  </div>
</template>
<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      search:'',
      reverse:'',
      queryInfo: {
        query: "",
        pagesize: 10,
        pagenum: 1,
      },
      orderList: [
        {
          id: 1,
          order_number: "1",
          order_price: 2221,
          pay_status: "1",
          is_send: "",
          create_time: "2021-9-10",
        },
        {
          id: 2,
          order_number: "2",
          order_price: 560560,
          pay_status: "2",
          is_send: "0",
          create_time: "2021-9-10",
        },
        {
          id: 1,
          order_number: "3",
          order_price: 520520,
          pay_status: "1",
          is_send: "0",
          create_time: "2021-9-10",
        },
        {
          id: 1,
          order_number: "4",
          order_price: 693965,
          pay_status: "1",
          is_send: "0",
          create_time: "2021-9-10",
        },
      ],
      total: 0,
      editBoxDialogVisible: false,
      addressForm: {
        address1: [],
        address2: "",
      },
      addressFormRules: {
        address1: [
          { required: true, message: "请选择所属省市区县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请填写详细地址", trigger: "blur" },
        ],
      },
      // 如果和赋值一样，可以简写
      cityData,
      ProgressDialogVisible: false,
      progressInfo: [],
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //是否发货
    issend(index,row){
      console.log(index,row);
     
     this.orderList.is_send=row.is_send="1";
    },
    getOrderList() {
      // const { data: res } = await this.$http.get('orders', {
      //   params: this.queryInfo
      // })
      // // console.log(res)
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取订单列表失败')
      // }
      // this.orderList = res.data.goods
      // this.total = res.data.total
    },
    handleSizeChange() {
      // this.queryInfo.pagesize = newsize
      // this.getOrderList()
    },
    // 监听页码值改变的事件
    handleCurrentChange() {
      // this.queryInfo.pagenum = newPage
      // this.getOrderList()
    },
    // 修改按钮
    showBox() {
      this.editBoxDialogVisible = true;
    },
    addressDialogClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    async showProgressBox() {
      // const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取物流信息失败')
      // }
      // this.progressInfo = res.data
      // // console.log(this.progressInfo)
      this.ProgressDialogVisible = true;
    },
    showSearch() {
      this.getOrderList();
    },
    //地址确认
    confirm(){
      console.log(this.addressForm);
    },
    //刷新
    handleRefresh(){
     location.reload();
    },
    //添加
    handleAdd(){
      this.dialogFormVisible=true;
    }
  },
};
</script>
<style  scoped>
.el-cascader {
  width: 100%;
}
</style>
